package com.tanhua.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {
    /**
     *  统计今日新增用户数
     * @param today
     * @return
     */
    @Select("select count(1) from tb_log where log_time=#{today} and type='0102'")
    Integer countNumRegisteredToday(String today);

    /**
     * 活跃用户数
     * @param today
     * @return
     */
    @Select("select count(distinct user_id) from tb_log where log_time=#{today}")
    Integer countNumActiveByDate(String today);

    /**
     * 登陆次数
     * @param today
     * @return
     */
    @Select("select count(1) from tb_log where log_time=#{today} and type in ('0101')")
    Integer countNumLoginByDate(String today);

    /**
     * 次日留存用户数
     * @param today
     * @param yesterday
     * @return
     */
    @Select("select count(distinct user_id) from tb_log where log_time=#{today} and user_id in (select user_id from tb_log where log_time=#{yesterday} and type = '0102')")
    Integer countNumRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);

}